{extend name="index/index" /}
{block name="main"}
 <div class="content-wrapper">
      <div class="page-title">
        <div>
          <h1><i class="fa fa-th-list"></i>  图片列表</h1>
          <p>Table to display analytical data effectively</p>
        </div>
        <div>
          <ul class="breadcrumb side">
            <li><i class="fa fa-home fa-lg"></i></li>
            <li>Tables</li>
            <li class="active"><a href="#">Data Table</a></li>
          </ul>
        </div>
      </div>
      <div class="row">
        <div class="col-md-12 pa">
        <a class='btn btn-info' href='/admin/label/create'>新增图片</a>
        </div>
      </div>
      <div class="row">
        <div class="col-md-12">
          <div class="card">
            <div class="card-body">
              <table class="table table-hover table-bordered" id="sampleTable">
                <thead>
                  <tr>
                    <th>id</th>
                    <th>父级</th>
                    <th>路径</th>
                    <th width='80'>状态</th>
                    <th width='150'>操作</th>
                  </tr>

                </thead>
                <tbody>
                  {volist name="list" id="v"}
                      <tr class="uid{$v.id}">
                          <td>{$v.id}</td>
                          <td><strong>{$v.pid}</strong></td>
                          <td><strong>{$v.url}</strong></td>
                          <td >
                            <div class="toggle lg">
                              <label>
                                <input type="checkbox" class='labelstatus' {$v.status?'checked':''} ><span class="button-indecator"></span>
                              </label>
                            </div>
                          </td>
                        <td>
                          <a class="btn-sm btn-danger" onclick='del("{$v.id}")' ><i
                          class="fa fa-trash-o fa-fw"></i></a>
                          <a class="btn-sm btn-success" href='/admin/label/edit/id/{$v.id}'><i
                          class="fa fa-edit"></i></a>
                          <a  data-toggle="tooltip" title="详情" class="btn-sm btn-info" href='/admin/label/getinfo/id/{$v.id}'>
                            <i class="fa fa-file-text-o fa-fw"></i></a>
                        </td>
                      </tr>
                  {/volist}
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>
<script>
  
$(document).ready(function(){
  // 点击获取角色权限
  $(".jssq").click(function(){
      var id = $(this).attr("uid");
      $.ajax({ 
        url:"/admin/label/getrole/id/"+id,
        type:'json',
        success: function(data){
          data = JSON.parse(data);
          $('#allnodes').empty()
          for (var i = 0; i < data.length; i++) {
            if (data[i].status == 1) {
                $('<label class="col-md-3 mp"> <input type="checkbox" checked value="'+data[i].id+'" class="changerole" ><span class="label-text"></span>'+data[i].name+'</label>').appendTo('#allnodes');
            }else{
                $('<label class="col-md-3 mp"> <input type="checkbox" value="'+data[i].id+'" class="changerole" ><span class="label-text"> </span>'+data[i].name+'</label>').appendTo('#allnodes');
            };
        }
        $('.changerole').change(function() { 
              var status = $(this).is(':checked');
              if (status==true) {status=1};
              if (status==false) {status=0};
              var rid = $(this).val();
              var uid = id;
              var url ='/admin/label/changerole/';
               $.get(url,{uid:uid,rid:rid,status:status},function(data){
                motai(data);
               });
          });
      }});
});


// 点击修改用户状态
$('.labelstatus').change(function() { 
      var status = $(this).is(':checked');
      if (status==true) {status=1};
      if (status==false) {status=0};
      var uid = $(this).parents('tr').attr('class').substring(3);
      var url ='/admin/label/changest/';
       $.get(url,{id:uid,status:status},function(data){
        motai(data);
       });

});
});

// 通过id删除

function del(id){
  $.ajax({
      type: 'delete',
      url: '/admin/label/' + id,
      dataType : 'json',
      success : function (data){
          // console.log(data);
      $('.uid'+id).empty();
      motai(data);
      },
      error : function () {
          motai('AJAX执行失败!');
      }
  });
}

</script>
{/block}
